#include "common/pch.h"
#include "map/instance_data.h"

#include <format>

#include <cftf/loger/syslog.h>

#include "map/map.h"

void InstanceData::SaveToDB() const
{
    // no reason to save BGs/Arenas
    if (instance->IsBattleGround())
    {
        return;
    }

    if (!Save())
    {
        return;
    }

    std::string data = Save();
#if 0
    CharacterDatabase.escape_string(data);

    if (instance->Instanceable())
    {
        CharacterDatabase.PExecute("UPDATE `instance` SET `data` = '%s' WHERE `id` = '%u'", data.c_str(), instance->GetInstanceId());
    }
    else
    {
        CharacterDatabase.PExecute("UPDATE `world` SET `data` = '%s' WHERE `map` = '%u'", data.c_str(), instance->GetId());
    }
#endif
}

bool InstanceData::CheckConditionCriteriaMeet(battle::object::Player const* /*source*/, unsigned int instance_condition_id, battle::object::WorldObject const* /*conditionSource*/, unsigned int conditionSourceType) const
{
    cftf::loger::SysLog::Instance().Error(std::format("Condition system call InstanceData::CheckConditionCriteriaMeet but instance script for map {} not have implementation for player condition criteria with internal id {} (called from {})",
        instance->GetId(), instance_condition_id, (unsigned int)(conditionSourceType)));
    return false;
}
